<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\MaterialController;
use App\Http\Controllers\TypeController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\InventoryController;
use App\Http\Controllers\OperationLogController;

// 认证路由
Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('login', [LoginController::class, 'login']);
Route::post('logout', [LoginController::class, 'logout'])->name('logout');

// 需要认证的路由
Route::middleware(['auth'])->group(function () {
    // 仪表盘
//    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/', [MaterialController::class, 'index'])->name('materials.index');
    // 材料管理
    Route::middleware(['role:admin'])->group(function () {
//        Route::get('materials', [MaterialController::class, 'index'])->name('materials.index');
        Route::get('materials/create', [MaterialController::class, 'create'])->name('materials.create');
        Route::post('materials', [MaterialController::class, 'store'])->name('materials.store');
        Route::get('materials/{material}/edit', [MaterialController::class, 'edit'])->name('materials.edit');
        Route::put('materials/{material}', [MaterialController::class, 'update'])->name('materials.update');
        Route::delete('materials/{material}', [MaterialController::class, 'destroy'])->name('materials.destroy');

        Route::get('types', [TypeController::class, 'index'])->name('types.index');
        Route::get('types/create', [TypeController::class, 'create'])->name('types.create');
        Route::post('types', [TypeController::class, 'store'])->name('types.store');
        Route::get('types/{type}/edit', [TypeController::class, 'edit'])->name('types.edit');
        Route::put('types/{type}', [TypeController::class, 'update'])->name('types.update');
        Route::delete('types/{type}', [TypeController::class, 'destroy'])->name('types.destroy');

        Route::get('users', [UserController::class, 'index'])->name('users.index');
        Route::get('users/create', [UserController::class, 'create'])->name('users.create');
        Route::post('users', [UserController::class, 'store'])->name('users.store');
        Route::get('users/{user}/edit', [UserController::class, 'edit'])->name('users.edit');
        Route::put('users/{user}', [UserController::class, 'update'])->name('users.update');
        Route::delete('users/{user}', [UserController::class, 'destroy'])->name('users.destroy');
        Route::post('users/{user}/reset-password', [UserController::class, 'resetPassword'])->name('users.reset-password');
    });

    Route::get('materials/export', [MaterialController::class, 'export'])->name('materials.export');

    // 出入库管理
    Route::get('inventory', [InventoryController::class, 'index'])->name('inventory.index');
    Route::get('inventory/create-in', [InventoryController::class, 'createIn'])->name('inventory.create-in');
    Route::get('inventory/create-out', [InventoryController::class, 'createOut'])->name('inventory.create-out');
    Route::post('inventory/store-in', [InventoryController::class, 'storeIn'])->name('inventory.store-in');
    Route::post('inventory/store-out', [InventoryController::class, 'storeOut'])->name('inventory.store-out');
    Route::get('inventory/export', [InventoryController::class, 'export'])->name('inventory.export');

    // 用户个人资料
    Route::get('profile', [UserController::class, 'profile'])->name('profile');
    Route::post('profile/update-password', [UserController::class, 'updatePassword'])->name('profile.update-password');

    // 操作日志
    Route::get('logs', [OperationLogController::class, 'index'])->name('logs.index');
    Route::get('logs/export', [OperationLogController::class, 'export'])->name('logs.export');
});
